<template>

    <body>
        <!-- 总容器 -->
        <div class="wrapper">
            <header>
                <i class="fa fa-angle-left" onclick="history.go(-1)"></i>
                <p>确认您的订单</p>
                <div></div>
            </header>
            <div class="top-ban"></div>

            <section>
                <div class="title">
                    <p>体检人信息</p>
                </div>
                <table>
                    <tr>
                        <td>姓名:</td>
                        <td>{{ user.realname }}</td>
                    </tr>
                    <tr>
                        <td>证件号码:</td>
                        <td>{{ user.identitycard }}</td>
                    </tr>
                    <tr>
                        <td>出生日期:</td>
                        <td>{{ user.birthday }}</td>
                    </tr>
                    <tr>
                        <td>手机号码:</td>
                        <td>{{ user.userid }}</td>
                    </tr>
                </table>
                <div class="title">
                    <p>体检日期</p>
                </div>
                <table>
                    <tr>
                        <td>{{ day.selectDay }}</td>
                    </tr>
                </table>
                <div class="title">
                    <p>体检机构</p>
                </div>
                <table>
                    <tr>
                        <td colspan="2">{{ hosp.name }}</td>
                    </tr>
                    <tr>
                        <td>营业时间:</td>
                        <td>{{ hosp.businesshours }}</td>
                    </tr>
                    <tr>
                        <td>采血截止:</td>
                        <td>{{ hosp.deadline }}</td>
                    </tr>
                    <tr>
                        <td>机构电话:</td>
                        <td>{{ hosp.telephone }}</td>
                    </tr>
                    <tr>
                        <td>机构地址:</td>
                        <td>{{ hosp.address }}</td>
                    </tr>
                </table>
                <div class="title">
                    <p>套餐类型</p>
                </div>
                <table>
                    <tr>
                        <td>{{ smname }}</td>
                    </tr>
                </table>
            </section>

            <div class="bottom-btn">
                <div class="first">实付款: <span>￥{{ price }}</span></div>
                <div class="last" @click="addorder">确认支付</div>
            </div>

            <div class="bottom-ban"></div>
            <global-footer></global-footer>
        </div>
    </body>
</template>

<script>
import { getSessionStorage, removeSessionStorage } from '../router/common.js'
import { reactive, toRefs } from 'vue';
import axios from '../router/axios';
import { useRouter, useRoute } from "vue-router";
export default {
    setup() {
        const router = useRouter();
        const route = useRoute();
        const state = reactive({
            user: {
                userid: "",
                identitycard: "",
                realname: "",
                birthday: "",
            },
            hosp: {
                hpId: route.query.hpId,
                // smId: route.query.smid, 
                address: "",
                businesshours: "",
                deadline: "",
                telephone: "",
                name: "",
            },
            day: {
                selectDay: route.query.selectDay,
            },
            smId: route.query.smId,
            smname: "",
            price: "",
            order: {
                orderid: "",
                orderdate: route.query.selectDay,
                userid: getSessionStorage("users").userid,
                smid: route.query.smId,
                state: 1,
                hpId: route.query.hpId,
            }
        });
        getuseriffo();
        function getuseriffo() {
            let userinfo = getSessionStorage("users")
            state.user.userid = userinfo.userid;
            state.user.identitycard = userinfo.identitycard;
            state.user.realname = userinfo.realname;
            state.user.birthday = userinfo.birthday;
            axios.get('/api/hospital/gethospitalById', {
                params: {
                    id: state.hosp.hpId,
                }
            })
                .then(function (response) {
                    const result = response.data;
                    state.hosp.address = result.data.address;
                    state.hosp.businesshours = result.data.businesshours;
                    state.hosp.deadline = result.data.deadline;
                    state.hosp.telephone = result.data.telephone;
                    state.hosp.name = result.data.name;
                })
                .catch(function (error) {
                    // 错误处理
                    console.log(error);
                })
                .finally(function () {
                    // 总是执行
                });
            axios.get('/api/setmeal/findbysmId', {
                params: {
                    smId: state.smId,
                }
            })
                .then(function (response) {
                    const result = response.data.data;
                    state.smname = result.name;
                    state.price = result.price;
                })
                .catch(function (error) {
                    // 错误处理
                    console.log(error);
                })
                .finally(function () {
                    // 总是执行
                });
        }
        function addorder() {
            axios.post('/api/orders/addorders', {
                orderid: state.order.orderid,
                hpid: state.order.hpId,
                orderdate: state.order.orderdate,
                smid: state.order.smid,
                state: state.order.state,
                userid: state.order.userid,
            })
                .then(function (response) {
                    const result = response.data;
                    console.log(result)
                    if (result.code == 1) {
                        window.open(`api/alipay/pay?subject=${state.smname}&traceNo=${result.data.orderid}&totalAmount=${state.price}`, "_self");
                    } else {
                        alert(result.msg)
                    }
                })
                .catch(function (error) {
                    // 错误处理
                    console.log(error);
                })
                .finally(function () {
                    // 总是执行
                });
        }
        // function toalipay(orderid) {
        //     axios.post('/api/alipay/pay',{
        //         orderid: orderid,
        //     })
        //         .then(function (response) {
        //             // 成功处理
        //             let result = response.data
        //             console.log(result.data);
        //             if (result.code == 1) {
        //                 const blob = new Blob([result.data], { type: "text/html" });
        //                 const url  = URL.createObjectURL(blob);
        //                 window.open(url,'_blank');
        //             }
        //             // alert("预约成功！")
        //             // router.push("/appointmentsuccess")
        //         })
        //         .catch(function (error) {
        //             // 错误处理
        //             console.log(error);
        //         })
        //         .finally(function () {
        //             // 总是执行
        //         });
        // }
        function toindex() {
            router.push("/index")
        }
        function topersonal() {
            router.push("/personal")
        }
        return {
            ...toRefs(state),
            toindex,
            topersonal,
            getuseriffo,
            addorder,
            // toalipay
        };
    }
}


</script>

<style scoped>
/*********************** 总容器 ***********************/
.wrapper {
    width: 100%;
    height: 100%;
    background-color: #F9F9F9;
}

/*********************** header ***********************/
header {
    width: 100%;
    height: 15.7vw;
    background-color: #FFF;

    position: fixed;
    left: 0;
    top: 0;

    display: flex;
    align-items: center;
    justify-content: space-between;

    box-sizing: border-box;
    padding: 0 3.6vw;
}

header .fa {
    font-size: 8vw;
}

/*********************** footer ***********************/
footer {
    width: 100%;
    height: 14.2vw;
    box-sizing: border-box;
    border-top: solid 1px #E9E9E9;
    background-color: #FFF;

    position: fixed;
    left: 0;
    bottom: 0;
}

footer ul {
    width: 100%;
    height: 14.2vw;
    display: flex;
    align-items: center;
    justify-content: space-around;
}

footer ul li {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    font-size: 3vw;
    color: #999;

    user-select: none;
    cursor: pointer;
}

footer ul li .fa {
    font-size: 5vw;
}

/*********************** common样式 ***********************/
.top-ban {
    width: 100%;
    height: 15.7vw;
}

.bottom-ban {
    width: 100%;
    height: 26.2vw;
}

/*********************** section ***********************/
section {
    width: 86vw;
    margin: 0 auto;
}

section .title {
    width: 100%;
    height: 12vw;
    border-bottom: solid 1px #EEE;

    display: flex;
    align-items: center;
}

section .title p {
    height: 3.4vw;
    line-height: 3.4vw;
    font-size: 4.2vw;
    font-weight: 600;
    box-sizing: border-box;
    padding-left: 3vw;
    border-left: solid 2px #127A90;
}

section table {
    font-size: 3.6vw;
    color: #555;
    margin-top: 2vw;
}

section table tr {
    line-height: 8vw;
}

section table tr td:first-child {
    width: 22%;
}

/*********************** bottom-btn ***********************/
.bottom-btn {
    width: 100%;
    height: 12vw;
    background-color: #FFF;

    position: fixed;
    left: 0;
    bottom: 14.2vw;

    display: flex;
}

.bottom-btn .first {
    flex: 2;
    line-height: 12vw;
    font-size: 4.6vw;
    box-sizing: border-box;
    padding-left: 6vw;
}

.bottom-btn .first span {
    color: #F77B2D;
}

.bottom-btn .last {
    flex: 1;
    background-color: #117C94;
    line-height: 12vw;
    text-align: center;
    font-size: 5vw;
    color: #FFF;

    user-select: none;
    cursor: pointer;
}
</style>